﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ERPStudio
{
    
    public partial class MessageBoxFrm : Form
    {
        private Int16 ButtonCount = 0;
        private int ButtonWidth = 0;
        private int ButtonDistance = 10;
        private Object errRow = null;
        public enum ImaginiMB { StopIcon, InformareIcon, IntrebareIcon, ExclamareIcon, SeLucreazaIcon } ;

        public MessageBoxFrm(String captionText, String messageText, String mesajBaza, ImaginiMB imagine, Object obj)
        {

            InitializeComponent();
            Text = captionText;
            TextLabel.Text = messageText;
            MesajLabel.Text = mesajBaza;
            errRow = obj;

            if (obj != null)
                propertyGrid1.SelectedObject = errRow;
            switch (imagine)
            { 
                case ImaginiMB.StopIcon:
                    pictureBoxStop.Visible = true;
                    pictureBoxInformare.Visible = false;
                    pictureBoxIntrebare.Visible = false;
                    pictureBoxExclamare.Visible = false;
                    pictureBoxSeLucreaza.Visible = false;
                    break;
                case ImaginiMB.InformareIcon:
                    pictureBoxStop.Visible = false;
                    pictureBoxInformare.Visible = true;
                    pictureBoxIntrebare.Visible = false;
                    pictureBoxExclamare.Visible = false;
                    pictureBoxSeLucreaza.Visible = false;
                    break;
                case ImaginiMB.IntrebareIcon:
                    pictureBoxStop.Visible = false;
                    pictureBoxInformare.Visible = false;
                    pictureBoxIntrebare.Visible = true;
                    pictureBoxExclamare.Visible = false;
                    pictureBoxSeLucreaza.Visible = false;
                    break;
                case ImaginiMB.ExclamareIcon:
                    pictureBoxStop.Visible = false;
                    pictureBoxInformare.Visible = false;
                    pictureBoxIntrebare.Visible = false;
                    pictureBoxExclamare.Visible = true;;
                    pictureBoxSeLucreaza.Visible = false;
                    break;
                default:
                    pictureBoxStop.Visible = false;
                    pictureBoxInformare.Visible = false;
                    pictureBoxIntrebare.Visible = false;
                    pictureBoxExclamare.Visible = false;
                    pictureBoxSeLucreaza.Visible = true;
                    break;
            }

        }

        public void AddButton(String text,int width, EventHandler functie)
        {
            ButtonList.Add(new Button());
            //ButtonList[ButtonCount].Location = new System.Drawing.Point(124, 11);
            ButtonList[ButtonCount].Name = "Button" + ButtonCount.ToString();
            ButtonList[ButtonCount].Size = new System.Drawing.Size(75, 23);
            ButtonList[ButtonCount].TabIndex = 0;
            ButtonList[ButtonCount].Text = text;
            ButtonList[ButtonCount].UseVisualStyleBackColor = true;
            ButtonList[ButtonCount].Width = width;
            if(functie !=null)
                ButtonList[ButtonCount].Click += new EventHandler(functie);
            else
                ButtonList[ButtonCount].Click += new EventHandler(MessageBoxFrm_Click_OK);
            ButtonWidth += width;
            this.splitContainer1.Panel2.Controls.Add(ButtonList[ButtonCount]);
            int xDepl = (this.splitContainer1.Panel2.Width - ButtonWidth - (ButtonList.Count)*ButtonDistance);
            int yDepl = (this.splitContainer1.Panel2.Height - ButtonList[ButtonCount].Height) / 2 -3 ;
            ButtonCount++;
            ///calculeaza pozitia exacta a butoanelor
            foreach (Button btn in ButtonList)
            {
                btn.Location = new System.Drawing.Point(xDepl, yDepl);
                xDepl += btn.Width + ButtonDistance;
            }
        }

        public void MessageBoxFrm_Click_OK(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        public void MessageBoxFrm_Click_Cancel(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        public void MessageBoxFrm_Click_Yes(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Yes;
            this.Close();
        }

        public void MessageBoxFrm_Click_No(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.No;
            this.Close();
        }

        private void MessageBoxFrm_Load(object sender, EventArgs e)
        {
            if (ButtonList.Count > 0)
            {
                ButtonList[0].Select();
                ButtonList[0].Focus();
            }
        }

 
    }
}
